/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Prestahop_retrievement;

import com.insa.a1.hibernate.ps.PsCart;
import com.insa.a1.hibernate.ps.PsCartProduct;
import com.insa.a1.xmladapter.DateAdapter;
import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import org.eclipse.persistence.oxm.annotations.XmlInverseReference;

/**
 *
 * @author strokyl
 */
@Entity
public class Cart implements Serializable {

    @Id
    private int idCart;

    @Temporal(TemporalType.TIMESTAMP)
    @XmlJavaTypeAdapter(DateAdapter.class)
    private Date dateUppAdd;

    @OneToMany(cascade=CascadeType.ALL, mappedBy="cartProductPK.cart")
    private Set<CartProduct> cartProducts;

    @OneToOne(mappedBy="cart")
    @XmlInverseReference(mappedBy = "cart")
    private Orders orders;

    public Cart() {
    }

    

    public Cart(PsCart ps, Orders orders) {
        this.idCart = ps.getIdCart();
        this.dateUppAdd = ps.getDateUpd();
        this.orders =orders;
        this.cartProducts = new HashSet<CartProduct>();
        for(PsCartProduct psP : ps.getCartProducts()) {
            cartProducts.add(new CartProduct(psP, this));
        }
    }

    public Set<CartProduct> getCartProducts() {
        return cartProducts;
    }

    public void setCartProducts(Set<CartProduct> cartProducts) {
        this.cartProducts = cartProducts;
    }

    

    public Date getDateUppAdd() {
        return dateUppAdd;
    }

    public void setDateUppAdd(Date dateUppAdd) {
        this.dateUppAdd = dateUppAdd;
    }

    public int getIdCart() {
        return idCart;
    }

    public void setIdCart(int idCart) {
        this.idCart = idCart;
    }

    public Orders getOrders() {
        return orders;
    }

    public void setOrders(Orders orders) {
        this.orders = orders;
    }

    @Override
    public String toString() {
        return String.format("Cart( %d )", idCart );
    }


    
}
